﻿using System;
using System.Linq;

namespace 第五次课堂作业
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            //countGDBH();
            linq();
        }

        public static void countGDBH()
        {
            int[] array = new int[190];
            for(int i = 6;i <= 100;i += 2)
            {
                for(int j = 3;j < i - 2;j += 2)
                {
                    if(isPrime(j) && isPrime(i - j))
                    {
                        Console.WriteLine(i + "可以由{0}和{1}两个素数构成.", j, i - j);
                        break;
                    }
                }

            }
        }

        public static bool isPrime(int i)
        {
            for (int j = 2; j < i; j++)
            {
                if (i % j == 0) return false;
            }
            return true;
        }

        public static void linq()
        {
            int i;
            double sum = 0;
            int[] arr = new int[100];
            Random random = new Random();

            for (i = 0; i < arr.Length; i++)
            {
                arr[i] = random.Next(1001) + 1;
            }
            var arr_sort = arr.Select(x => x).OrderByDescending(x => x).ToArray();
            for (i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("{0}", arr_sort[i]);
                sum += arr_sort[i];
            }
            Console.WriteLine("求和：{0}", sum);
            Console.WriteLine("平均值：{0:0.0000}", sum / 100);
        }
    }
}
